//
//  MVVM-V.m
//  DesignPattern
//
//  Created by jun on 2021/4/16.
//

#import "MVVM-V.h"
#import <ReactiveObjC/RACEXTScope.h>
#import <ReactiveObjC/RACSignal.h>
#import <ReactiveObjC/UIControl+RACSignalSupport.h>

@interface MVVM_V ()

@property UIButton *bt;

@end

@implementation MVVM_V

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.bt = [[UIButton alloc]initWithFrame:frame];
        [self addSubview:self.bt];
        
        @weakify(self);
        //RAC 1 发送消息
        [[self.bt rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            NSLog(@"execute");
            [self.vm.updateDataCommand execute:@{
                @"type":@(2)
            }];
        }];
    }
    return self;
}

- (void)reloadView:(UIColor *)color{
    self.backgroundColor = color;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    !self.touchBlock?:self.touchBlock();
}

@end
